﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ServiceName : AppServices
{
    ProxyWrapper.ServicesServiceWrapper _srvWrapper = null;
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        if (!Page.IsPostBack)
        {
            string serviceName = Request["name"] != null ? Request["name"].ToString() : SrvDetails.ServiceName;
            string serviceDetail = Request["description"] != null ? Request["description"].ToString() : SrvDetails.ServiceDescription;
            _srvWrapper = new ProxyWrapper.ServicesServiceWrapper();
            _srvWrapper.UpdateService(UserDetails,ServiceId, serviceName, serviceDetail);
            //Response.Redirect("", false);
        }
        if (Request["database"] != null && Request["duplicateValue"]!=null)
        {
            try
            {
                ProxyWrapper.DatabaseServiceWrapper _dbService = new ProxyWrapper.DatabaseServiceWrapper();
                _srvWrapper = new ProxyWrapper.ServicesServiceWrapper();
                string dbId = Request["database"] != null ? Request["database"] : "0";
                int[] serviceIds = new int[1];
                serviceIds[0] = ServiceId;

                if (Request["newDatabaseName"] != null && !string.IsNullOrWhiteSpace(Request["newDatabaseName"].ToString()))
                {
                    int tmpdbId = 0;
                    string[] msg = _dbService.AddDatabase(Request["newDatabaseName"].ToString(), false, UserDetails.ClientId, null, null);
                    if (Int32.TryParse(msg[0].ToString(), out tmpdbId) && tmpdbId > 0)
                    {
                        dbId = msg[0].ToString();
                    }
                }

              string result=  _srvWrapper.AssociateDBToService(Convert.ToInt32(dbId), serviceIds, UserDetails.ClientId);
            }
            catch (Exception ex) { }
             
        }
    }
}